/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import Bean.Pemesanan;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Yohanes Beny P
 */
@WebServlet(urlPatterns = {"/PesanStokCabang"})
public class PesanStokCabang extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        Cookie ck[] = request.getCookies();
        String id = ck[1].getValue();
        String tgl = request.getParameter("date_brg");
        String kode = request.getParameter("kode_brg");
        String jum = request.getParameter("jmlh_brg");

        Bean.Pemesanan psn = new Pemesanan();
        String kode1 = psn.generateKodePemesanan(tgl, id);
        String kode2 = psn.kodePemesenanFinal(kode1);
        psn.setId_cab(id);
        psn.setJmlh(jum);
        psn.setKode_brg(kode);
        psn.setKode_pemesanan(kode2);
        psn.setTgl_pesan(tgl);

        psn.tambahPemesanan(psn);

        out.println("<html>");
        out.println("<head>");
        out.println("<title>Status Tambah Stok Pusat Frogstone</title>");
        out.println("<link href=\"css/style_web.css\" rel=\"stylesheet\" type=\"text/css\"/>");
        out.println("</head>");
        out.println("<body id=\"home\">");
        out.println("<div id=\"wrapper\">");
        out.println("<div id=\"header\">");
        out.println("<div id=\"site_title\">");
        out.println("<a href=\"#\"></a>");
        out.println("</div>");
        out.println("<div id=\"header_kanan\">");
        out.println("</div>");
        out.println("<div id=\"content\">");
        out.println("<center>");
        out.println("<h2><b><font color=\"red\" face=\"Verdana\">PROSES PESAN BERHASIL....!!!</font></b></h2></br>");
        out.println("<form action=\"MenuUtamaCabang.jsp\"><input type=\"submit\" name=\"submit\" value=\"KEMBALI\"/></form>");
        out.println("</center>");
        out.println("</div>");
        out.println("</div>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");

    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(PesanStokCabang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(PesanStokCabang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
